import requests
import re

# 通过pip安装包时，还可以通过设置镜像站点的方式，提高下载速度。
# pip install requests -i https://mirrors.aliyun.com/pypi/simple/

result = requests.get('https://www.qschina.cn/sites/default/files/qs-rankings-data/cn/2005378.txt?_=1589199262488')
# data = result.text.encode().decode('unicode_escape')
data = result.json()
# print(type(data))
# print(data['data'][0]['title'])



regex = r"<a.*?>(.*?)<\\/a>"

test_str = (data['data'][0]['title'])

content = data['data'][0]['title']
pattern = re.compile('<a.*?>(.*?)<\\/a>')
result = re.search(pattern, content)
print(result.group(1))

# result = re.findall(pattern, content)
# print(result)
# 汉字编码转换

# str = '\u7ea6\u7ff0\u970d\u666e\u91d1\u65af\u5927\u5b66'
# print(str.encode().decode())

# # 保存到本地文件中
# f = open('./23/rankingsOfCommunication.txt','w',encoding='utf-8')
# # f.write(result.text.encode().decode('unicode_escape'))
# f.write(str)
# f.close()
